package com.ui_componet.list;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ui_componet.R;

import org.w3c.dom.Text;

/**
 * Created by tanghongbin on 2017/3/15.
 */

public class BindingRecycleView extends LinearLayout {
    private RecyclerView recycle;

    public BindingRecycleView(Context context) {
        super(context);
        init(context);
    }


    public BindingRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        setOrientation(VERTICAL);
//        SwipeRefreshLayout refreshLayout = new SwipeRefreshLayout(context);
//        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                Log.i("TAG","正在刷新");
//            }
//        });
        recycle = new RecyclerView(context);
//        refreshLayout.addView(recycle,new SwipeRefreshLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
//                ViewGroup.LayoutParams.MATCH_PARENT));
        recycle.setLayoutManager(new LinearLayoutManager(context));
        recycle.setAdapter(new RecyclerView.Adapter<Holder>() {
            @Override
            public Holder onCreateViewHolder(ViewGroup parent, int viewType) {

                TextView textView = new TextView(getContext());
                return new Holder(textView);
            }

            @Override
            public void onBindViewHolder(Holder holder, int position) {
                holder.textView.setText("sdfsdfsf");
            }


            @Override
            public int getItemCount() {
                return 30;
            }
        });
        addView(recycle,new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }
    public void setAdapter(RecyclerView.Adapter adapter){
        recycle.setAdapter(adapter);
    }

    public void setLayoutManager(RecyclerView.LayoutManager manager){
        recycle.setLayoutManager(manager);
    }
    class Holder extends RecyclerView.ViewHolder{

        TextView textView;


        public Holder(View itemView) {
            super(itemView);
            textView = (TextView) itemView;
            textView.setTextColor(getResources().getColor(R.color.black));
        }
    }
}
